﻿using System;
using System.Diagnostics;
using TI_BLE_HCI_ClientLib.HCIBaseEntities;
using TI_BLE_HCI_ClientLib.HCIEvents;
using Utilities;

namespace TI_BLE_HCI_ClientLib.HCIParsers
{
    public static partial class HCIEventParser
    {
        private static HCIEvent parseHCI_LE_ExtEvent_GAP_Link_Terminated(byte parsLen, byte[] buffer)
        {
            if (parsLen != 6) throw new ArgumentException("parseHCI_LE_ExtEvent_GAP_LinkTerminated Parameters Length != 6");
            byte bufIdx = 4;

            HCIVendorSpecificEventHostErrorCode status = (HCIVendorSpecificEventHostErrorCode)parseByteParameter(buffer, ref bufIdx);
            ushort connHandle = parseWordParameter(buffer, ref bufIdx);
            TI_BLE_HCI_ClientLib.HCIEvents.HCIEvent_GAP_Link_Terminated.ReasonEnum reason = (TI_BLE_HCI_ClientLib.HCIEvents.HCIEvent_GAP_Link_Terminated.ReasonEnum)parseByteParameter(buffer, ref bufIdx);

            var hciEvent = new HCIEvent_GAP_Link_Terminated(status, connHandle, reason);

            return hciEvent;
        }
    }
}
